<template>
	<view class="content">
		<!-- 顶部固定的那一栏 -->
		<view class="titHead">
			<view class="lefter">
				<view class="kefu">
					<image src="../../static/icons/kf.png" mode=""></image>
				</view>
			</view>
			<view class="righter">
				<view class="search">
					<image src="../../static/icons/search-active.png"></image>
				</view>
				<view class="cart">
					<image src="../../static/icons/cart2.png"></image>
				</view>
			</view>
		</view>
		<!-- 轮播图 -->
		<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item class="swiperItem" v-for="item in swiperList" :key="item.id">
				<image :src="item.pic" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="navbir">
			<view class="navOne" v-for="item in navbirList" :key="item.id" @tap="gouxiangqing(item.id)">
				<view class="imger">
					<image :src="item.icon" mode=""></image>
				</view>
				<view class="names">
					{{item.name}}
				</view>
			</view>
		</view>
		<!-- 广告轮播图 -->
		<view class="adverd">
			<view class="iconfont icon-laba-copy icon"></view>
			<view class="huohost">限时活动:</view>
			<swiper class="sper" autoplay interval="3000" vertical circular>
				<swiper-item class="sperItem" v-for="item in advList" :key="item.recommendId" @click="gouGoods(item.recommendId)">
					<view class="shoName">
						{{item.name}}
					</view>
					<view class="jiage">
						<view class="yuanjia">
							{{item.price}}元
						</view>
						<view class="xianjia">
							现价：{{item.promotionPrice}}元
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 热门推荐 -->
		<view class="hosRecommend">
			<view class="commend">
				<heads :title="host"></heads>
			</view>
			<view class="hostcom">
				<swiper class="swiper" autoplay interval="2000" circular>
					<swiper-item class="swiperItem" v-for="item in hostList" :key="item.id" @click="gouGoods(item.id)">
						<image :src="item.pic" mode=""></image>
						<view class="textName">
							{{item.name}}
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- 新品推荐 -->
		<view class="newRecommend">
			<view class="commend">
				<heads :title="xin"></heads>
			</view>
			<!-- 295 130 -->
			<view class="newcomm">
				<view class="pic" @click="gouGoods(item.id)" v-for="item in newList" :key="item.id">
					<image :src="item.pic" mode=""></image>
					<view class="textNew">
						<view class="newName">
							{{item.name}}
						</view>
						<view class="newJiage">
							价格：{{item.price}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 猜你喜欢 -->
		<view class="likeRecommend">
			<view class="commend">
				<heads :title="cai"></heads>
			</view>
			<view class="likecomm">
				<view class="likegeshu" @click="gouGoods(item.id)" v-for="item in likeList" :key="item.id">
					<image :src="item.pic" mode=""></image>
					<view class="likeName">
						<view class="asyyds">
							{{item.brandName}}
						</view>
						<view class="bsyyds">
							<view class="csyyds">
								{{item.price}}元
							</view>
							<view class="dsttds">
								乐居
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import heads from "@/components/heads.vue"
	import {
		indexBannerApi,
		inisHomeFenLei,
		inisadverdList,
		inisHostList,
		inisNewList,
		inislikeList
	} from "../../api/index/index.js"

	export default {
		name: "index",
		components: {
			heads
		},
		data() {
			return {
				cai: "猜你喜欢",
				host: "热门推荐",
				xin: "新品推荐",
				// 轮播图
				swiperList: [],
				// 分类导航
				navbirList: [],
				// 显示广告
				advList: [],
				// 热门推荐
				hostList: [],
				// 新品推荐
				newList: [],
				likeList: []

			}
		},
		methods: {
			gouxiangqing(id) {
				uni.navigateTo({
					url: `/pages/fenleixiangqing/fenXiang/fenXiang?id=${id}`
				})
			},
			// 点击跳转 商品详情页
			gouGoods(id){
				uni.navigateTo({
					url:`/pages/goods/goods?id=${id}`
				})
			},
		},
		onLoad() {
			// const that = this;
			// 首页轮播
			indexBannerApi().then(res => {
				// console.log(res)
				this.swiperList = res.data.data.items
			});
			// 首页分类导航
			inisHomeFenLei("1308336521604599809").then(res => {
				// console.log(res)
				this.navbirList = res.data.data.category.children
			});
			// 首页广告轮播
			inisadverdList().then(res => {
				// console.log(res)
				this.advList = res.data.data.items
			});
			// 热门推荐
			inisHostList().then(res => {
				// console.log(res)
				this.hostList = res.data.data.items
			});
			// 新品推荐
			inisNewList(1, 10).then(res => {
				// console.log(res)
				this.newList = res.data.data.rows
			});
			// 猜你喜欢
			inislikeList().then(res => {
				// console.log(res)
				this.likeList = res.data.data.items
			})
		},
	}
</script>

<style lang="less">
	.content {
		position: relative;
		height: 100%;
		background-color: #f4e8ab;

		// 顶部固定那一栏
		.titHead {
			height: 42rpx;
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			position: fixed;
			top: 32rpx;
			left: 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			z-index: 9999;

			.lefter {
				.kefu {
					width: 42rpx;
					height: 42rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.righter {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.search {
					width: 42rpx;
					height: 42rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.cart {
					width: 42rpx;
					height: 42rpx;
					margin-left: 30rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}

		// 轮播图
		.swiper {
			width: 100%;
			height: 181px;

			.swiperItem {
				width: 100%;
				height: 181px;

				image {
					width: 100%;
					// height: 100%;
				}
			}
		}

		// 分类导航
		.navbir {
			width: 100%;
			height: 131rpx;
			margin: 30rpx 0;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.navOne {
				width: 125rpx;
				height: 131rpx;
				// text-align: center;
				display: flex;
				flex-direction: column;
				align-items: center;

				.imger {
					width: 83rpx;
					height: 83rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.names {
					font-size: 33rpx;
					color: #3e3e3e;
				}
			}
		}

		// 广告轮播图
		.adverd {
			width: 80%;
			height: 100rpx;
			margin: 41rpx auto;
			background-color: #fff;
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.icon {
				margin-left: 30rpx;
				width: 50rpx;
				height: 50rpx;
				color: #fbdc0e;
				font-size: 50rpx;
			}

			.huohost {
				width: 138rpx;
				height: 100rpx;
				font-size: 29rpx;
				font-weight: 700;
				line-height: 100rpx;
				color: #fbdc0e;
				box-sizing: border-box;
				padding: 0 0 0 10rpx;

			}

			.sper {
				flex: 1;
				height: 100rpx;
				display: flex;
				align-items: center;

				.sperItem {
					display: flex;
					align-items: center;

					.shoName {
						width: 60%;
						height: 100rpx;
						font-size: 29rpx;
						line-height: 100rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.jiage {
						width: 40%;
						height: 100rpx;
						box-sizing: border-box;
						font-size: 15rpx;
						font-weight: 600;
						padding: 20rpx 0 20rpx 6rpx;

						.yuanjia {
							height: 30rpx;
							line-height: 30rpx;
							text-decoration: line-through;
						}

						.xianjia {
							color: red;
							height: 30rpx;
							line-height: 30rpx;
						}
					}
				}
			}
		}

		// 热门推荐
		.hosRecommend {
			width: 100%;
			// height: 232rpx;
			padding: 0 40rpx;
			box-sizing: border-box;

			.commend {
				height: 83rpx;
				padding: 24rpx 0;
				box-sizing: border-box;
			}

			.hostcom {
				height: 150rpx !important;
				width: 100%;

				.swiper {
					height: 150rpx !important;

					.swiperItem {
						width: 35% !important;
						height: 150rpx !important;

						image {
							width: 104rpx;
							height: 88rpx;
							text-align: center;
						}

						.textName {
							width: 200rpx;
							text-align: center;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}
				}
			}

		}

		// 新品推荐
		.newRecommend {
			width: 100%;
			// height: 232rpx;
			padding: 0 40rpx;
			box-sizing: border-box;

			.commend {
				height: 83rpx;
				padding: 24rpx 0;
				box-sizing: border-box;
			}

			.newcomm {
				width: 100%;
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				overflow-x: auto;

				.pic {
					width: 295rpx;
					height: 130rpx;
					padding: 25rpx;
					box-sizing: border-box;
					flex-shrink: 0;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-right: 10rpx;
					background-color: #FFFFFF;

					image {
						width: 97rpx;
						height: 84rpx;
					}

					.textNew {
						width: 160rpx;
						height: 84rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						padding-left: 10rpx;
						box-sizing: border-box;

						.newName {
							height: 36rpx;
							font-size: 13rpx;
						}

						.newJiage {
							font-size: 13rpx;
						}
					}
				}
			}

		}

		// 猜你喜欢
		.likeRecommend {
			width: 100%;
			// height: 232rpx;
			padding: 0 40rpx;
			box-sizing: border-box;
			margin-bottom: 50rpx;

			.commend {
				height: 83rpx;
				padding: 24rpx 0;
				box-sizing: border-box;
			}

			.likecomm {
				font-size: 13rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				flex-wrap: wrap;

				.likegeshu {
					width: 162rpx;
					height: 208rpx;
					background-color: #fffdfe;

					image {
						width: 162rpx !important;
						height: 119rpx !important;
					}

					.likeName {
						width: 100%;
						padding: 18rpx;
						box-sizing: border-box;

						.asyyds {
							margin-bottom: 20rpx;
						}

						.bsyyds {
							display: flex;
							justify-content: space-between;

							.csyyds {}

							.dsyyds {}
						}
					}
				}
			}
		}
	}
</style>
